package com.system.manager.utils;

import com.system.manager.modules.assit.vo.RoleVo;
import com.system.manager.modules.authorized.vo.MenuVo;

import java.util.ArrayList;
import java.util.List;

/**
 * 用来处理菜单的子模块
 */
public class TreeUtil {

    public static List<MenuVo> toTree(List<MenuVo> treeList, Long pid) {
        List<MenuVo> retList = new ArrayList<MenuVo>();

        for (MenuVo parent : treeList) {
            if (pid.equals(parent.getPid())) {
                retList.add(findChildren(parent, treeList));
            }
        }
        return retList;
    }
    private static MenuVo findChildren(MenuVo parent, List<MenuVo> treeList) {
        for (MenuVo child : treeList) {
            if (parent.getId().equals(child.getPid())) {
                if (parent.getChild() == null) {
                    parent.setChild(new ArrayList<>());
                }
                parent.getChild().add(findChildren(child, treeList));
            }
        }
        return parent;
    }

    private static List<Integer> findChildren(List<RoleVo> roleVoList, Integer pid){
        List<Integer> roleChild = new ArrayList<>();

        roleVoList.forEach(roleVo -> {
            if(roleVo.getPid() == pid){

            }
        });


        return roleChild;
    }
}